﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using HYI.SDBSERVER;

namespace SHRBASE
{
    public partial class FMI_PACK_INV : SDBSERVER.FMSINGLE
    {
        //入口函数
        public static Int32 StartMe(string sMainPara, string sPara, string sUser, DBSERVER sDB)
        {
            StaticClass.Selectm_MainPara = sMainPara;
            StaticClass.SelectItemValue = sPara;
            StaticClass.SelectUser = sUser;
            StaticClass.myDB = sDB;
            return 0;
        }

        //DBSERVER myADO = new DBSERVER();
        DBCache myCache = new DBCache();
        private int iGridView = 0;

        public FMI_PACK_INV()
        {
            InitializeComponent();
        }

        //查询代码
        protected override void OnSys04()
        {
            string SQL = "select c.fdictname,a.fpackno,b.fpackname,a.frfidbarcode,d.fdictname fstate"
                + " from i_pack_inv a"
                + " inner join i_ts_pack b on a.fpackno=b.fpackno"
                + " inner join s_ts_dict c on c.fdicttype=3001 and c.fdictno=b.fstorageflag"
                + " inner join s_ts_dict d on d.fdicttype=1000 and d.fdictno=a.fstate"
                + "  where 1 = 1";
            DataRowView drv = (DataRowView)uiCBfstorageflag.SelectedItem;
            if ((drv != null) && (uiCBfstorageflag.SelectedIndex > 0))
            {
                string sfstorageflag = drv.Row["fDictNo"].ToString();
                SQL = SQL + " and c.fdictno='" + sfstorageflag + "'";
            }

            DataRowView drv2 = (DataRowView)cbfstate.SelectedItem;
            if ((drv2 != null) && (cbfstate.SelectedIndex > 0))
            {
                string sfstate = drv2.Row["fDictNo"].ToString();
                SQL = SQL + " and a.fstate='" + sfstate + "'";
            }

            if (qifpackno.Text != "")
            {
                SQL = SQL + " and ((b.fpackno like '%" + qifpackno.Text + "%')"
                 + " or (b.fpackname like '%" + qifpackno.Text + "%')"
                 + " or (a.frfidbarcode like '%" + qifpackno.Text + "%')"
                 + ")";
            }

            SQL = SQL + "  order by c.fdictname,a.fpackno";
            Qrytable = StaticClass.myDB.query(SQL);

            base.OnSys04();
            rowindex = -1;
            
        }

        private void FMI_PACK_INV_Load(object sender, EventArgs e)
        {
            sUser = StaticClass.SelectUser;
            string[] strArray = StaticClass.Selectm_MainPara.Split(new char[] { ';' });
            sMenu = strArray[1];

            //按钮控制
            sys01.Visible = false; sys01.Tag = "1";
            sys02.Visible = false; sys02.Tag = "1";
            sys03.Visible = false; sys03.Tag = "1";
            sys05.Visible = false; sys05.Tag = "1";
            sys07.Visible = false; sys07.Tag = "1";
            sys10.Visible = false; sys10.Tag = "1";
            sys11.Visible = false; sys11.Tag = "1";

            //下拉框
            DataTable myTs_Dict = myCache.doGetDict("S_TS_DICT", "fDictType=3001");

            DataRow dr1 = myTs_Dict.NewRow();
            dr1["fDictName"] = "请选择";
            dr1["fDictNo"] = "0";
            myTs_Dict.Rows.InsertAt(dr1, 0);

            uiCBfstorageflag.DataSource = myTs_Dict;
            uiCBfstorageflag.DisplayMember = "fDictName";
            uiCBfstorageflag.ValueMember = "fDictNo";
            uiCBfstorageflag.SelectedIndex = 0;

            DataTable myTs_State = myCache.doGetDict("S_TS_DICT", "fDictType=1000");

            DataRow dr2 = myTs_State.NewRow();
            dr2["fDictName"] = "请选择";
            dr2["fDictNo"] = "0";
            myTs_State.Rows.InsertAt(dr2, 0);

            cbfstate.DataSource = myTs_State;
            cbfstate.DisplayMember = "fDictName";
            cbfstate.ValueMember = "fDictNo";
            cbfstate.SelectedIndex = 0;

            //执行查询代码
            OnSys04();

            //表格列显示统一控制
            if (iGridView == 0)
            {
                myCache.doSetGridVIew(sMenu, sUser, uiDGView);
                iGridView = iGridView + 1;
            }
        }

        private void uiCBfstorageflag_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (iGridView > 0)
            {
                OnSys04();
            }
        }

        private void cbfstate_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (iGridView > 0)
            {
                OnSys04();
            }
        }
    }
}
